﻿@model MobilnyDostawca.ViewModels.PrzesylkiIndexFilterViewModel

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
    <legend>Filtry</legend>
    <fieldset>
        <legend>Nadawca</legend>
            <div class="editor-label">
            <label>Nadawca</label> 
            <label style="margin-left: 14%;">Region</label> 
            <label style="margin-left: 15%;">Subregion</label> 
            <label style="margin-left: 13%;">Dostawca</label> 
            <label style="margin-left: 13%;">Magazyn</label> 
            </div>
            <div class="editor-field">
                @Html.DropDownList("Nadawca", Model.Nadawcy, string.Empty, new { id = "NadawcaID", style="width: 19%;" })
                @Html.ValidationMessageFor(model => model.Nadawca)
                @Html.DropDownList("NadawcaRegion", Model.NadawcaRegiony, string.Empty, new { id = "NadawcaRegionyID", style="width: 19%;" })
                @Html.ValidationMessageFor(model => model.NadawcaRegion)
                @Html.DropDownList("NadawcaSubregion",Enumerable.Empty<SelectListItem>(), string.Empty, new { id = "NadawcaSubregionyID", style="width: 19%;" })
                @Html.ValidationMessageFor(model => model.NadawcaSubregion)
                @Html.DropDownList("NadawcaDostawca", Model.NadawcaDostawcy, string.Empty, new { id = "NadawcaDostawcaID", style="width: 19%;"})
                @Html.ValidationMessageFor(model => model.NadawcaDostawca)
                @Html.DropDownList("NadawcaMagazyn", Model.NadawcaMagazyny, string.Empty, new { id = "NadawcaMagazynID", style="width: 19%;"})
                @Html.ValidationMessageFor(model => model.NadawcaMagazyn)
            </div>
    </fieldset>
    <fieldset>
        <legend>Odbiorca</legend>
            <div class="editor-label">
            <label>Odbiorca</label> 
            <label style="margin-left: 14%;">Region</label> 
            <label style="margin-left: 15%;">Subregion</label> 
            <label style="margin-left: 13%;">Dostawca</label> 
            <label style="margin-left: 13%;">Magazyn</label> 
            </div>
            <div class="editor-field">
                @Html.DropDownList("Odbiorca", Model.Odbiorcy, string.Empty, new { id = "OdbiorcaID", style="width: 19%;" })
                @Html.ValidationMessageFor(model => model.Odbiorca)
                @Html.DropDownList("OdbiorcaRegion", Model.OdbiorcaRegiony, string.Empty, new { id = "OdbiorcaRegionyID", style="width: 19%;" })
                @Html.ValidationMessageFor(model => model.OdbiorcaRegion)
                @Html.DropDownList("OdbiorcaSubregion",Enumerable.Empty<SelectListItem>(), string.Empty, new { id = "OdbiorcaSubregionyID", style="width: 19%;" })
                @Html.ValidationMessageFor(model => model.OdbiorcaSubregion)
                @Html.DropDownList("OdbiorcaDostawca", Model.OdbiorcaDostawcy, string.Empty, new { id = "OdbiorcaDostawcaID", style="width: 19%;"})
                @Html.ValidationMessageFor(model => model.OdbiorcaDostawca)
                @Html.DropDownList("OdbiorcaMagazyn", Model.OdbiorcaMagazyny, string.Empty, new { id = "OdbiorcaMagazynID", style="width: 19%;"})
                @Html.ValidationMessageFor(model => model.OdbiorcaMagazyn)
            </div>
    </fieldset>
    <fieldset>
        <legend>Status</legend>
            <div class="editor-label">
                @Html.LabelFor(model => model.Status, "Status")
            </div>
            <div class="editor-field">
                @Html.DropDownList("Status", Model.Statusy, string.Empty, new { id = "StatusID" })
                @Html.ValidationMessageFor(model => model.Status)
            </div>
    </fieldset>
            <p>
                <input type="submit" value="Filtruj" title="Filtruj"/>
            </p>
</fieldset>
}
<script type="text/javascript">
    $('#NadawcaRegionyID').change(function () {
        var selectedRegion = $(this).val();
        if (selectedRegion != null && selectedRegion != '') {
            $.getJSON('@Url.Action("GetSubregionsForRegion")', { region: selectedRegion }, function (subregions) {
                var subregionsSelect = $('#NadawcaSubregionyID');
                subregionsSelect.empty();
                $.each(subregions, function (index, subregion) {
                    subregionsSelect.append($('<option/>', {
                        value: subregion.Value,
                        text: subregion.Text
                    }));
                });
            });
        }
    });
</script>

<script type="text/javascript">
    $('#OdbiorcaRegionyID').change(function () {
        var selectedRegion = $(this).val();
        if (selectedRegion != null && selectedRegion != '') {
            $.getJSON('@Url.Action("GetSubregionsForRegion")', { region: selectedRegion }, function (subregions) {
                var subregionsSelect = $('#OdbiorcaSubregionyID');
                subregionsSelect.empty();
                $.each(subregions, function (index, subregion) {
                    subregionsSelect.append($('<option/>', {
                        value: subregion.Value,
                        text: subregion.Text
                    }));
                });
            });
        }
    });
</script>